import { useRoute } from 'vue-router'
import { GetRoleMenuButtonsApi } from '@/api/role'
import { useUserStoreWithOut } from '@/store/modules/user'

/**
 * 按钮权限
 * @returns
 */

export const useButtonPermiss = async () => {
  const route = useRoute()
  const userStore = useUserStoreWithOut()
  // console.log('route', route.name, userStore.userInfo?.roleId)
  const roleGuid = userStore.userInfo?.roleId
  if (roleGuid == '-1') {
    return ['新增', '编辑', '删除', '导入', '导出']
  } else {
    const res = await GetRoleMenuButtonsApi({
      roleGuid,
      name: route.name as string
    })
    return res.data || []
  }
}

export const UploadUrlParams = () => {
  const PATH_URL = window.webkitURL.webApiBaseUrl || import.meta.env.VITE_API_BASE_PATH

  const userStore = useUserStoreWithOut()
  const uploadUrl = PATH_URL + 'api/User/ExportUsers'
  const headers = { Authorization: userStore.getToken ?? '' }
  return { uploadUrl, headers }
}
